package com.heima.wemedia.config;

import com.heima.common.constants.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DeclarePubArticleRabbitConfig {
    @Bean
    public DirectExchange delayDirect() {
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .delayed()//声明交换机
                .build();
    }

    @Bean
    public Queue queue() {
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE);
    }

    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(delayDirect()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }
}
